<?php

/**
 * 用户角色关系模型
 *
 * @author haifeng.wu
 */

class Application_Model_UserRole extends Application_Model_Common
{
    /**
     * 表名
     *
     * @var string
     */
    protected $_name= 'front_role_user';

    /**
     * 构造函数
     * 
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * 从角色ID获取所有用户名
     * @param int $roleId
     * @return array
     */
    public function getUserNamesByRoleId($roleId)
    {
    	$userModel = new Application_Model_User();
    	$sql = "select userName 
    	from `{$userModel->getTableName()}` 
    	where id in (
    		select userId from `{$this->getTableName()}`
    		where roleId = {$roleId}
    	)  	
    	";
    	
    	$res = array();
    	$rows = $this->_db->fetchAll($sql);
    	foreach($rows as $row) {
    		$res[]=$row['userName'];
    	}   	
    	return $res;   	
    }
}